package com.michael.study.jetpack.module.dsl.toast

import android.content.Context
import android.widget.Toast

class ToastWarpper {

    var context : Context? = null
    var msg : String? = null
    var resId : Int? = null
    var duration : Int = Toast.LENGTH_SHORT
}

fun toast(block : ToastWarpper.() -> Unit) {
    val wrapper = ToastWarpper()
    wrapper.block()
    if (wrapper.resId == null) {
        wrapper.msg?.let {
            Toast.makeText(wrapper.context, it, wrapper.duration).show()
        }
    } else {
        wrapper.resId?.let {
            Toast.makeText(wrapper.context, it, wrapper.duration).show()
        }
    }
}